package com.yunji.framework_template.web.controller;

import java.util.List;

import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.yunji.framework_template.biz.service.SitesTypeTopService;
import com.yunji.framework_template.common.web.Page;
import com.yunji.framework_template.common.web.Result;
import com.yunji.framework_template.orm.persistence.model.SitesTypeTop;

/**
 * Created by fenglibin on 2018/11/15.
 */
@Controller
@RequestMapping("/sitesTypeTop/")
public class SitesTypeTopController {

    @Autowired
    SitesTypeTopService sitesTypeTopService;

    @RequestMapping("selectAll")
    @ResponseBody
    public Result<List<SitesTypeTop>> selectAll() {
        return Result.success(sitesTypeTopService.selectAll());
    }

    @RequestMapping("select")
    @ResponseBody
    public Result<SitesTypeTop> selectByPrimaryKey(@Param("typeId") Integer typeId, @Param("siteId") Integer siteId) {
        return Result.success(sitesTypeTopService.selectByPrimaryKey(typeId, siteId));
    }

    @RequestMapping("selectByCondition")
    @ResponseBody
    public Result<List<SitesTypeTop>> selectByCondition(SitesTypeTop record) {
        return Result.success(sitesTypeTopService.selectByCondition(record));
    }

    @RequestMapping("count")
    @ResponseBody
    public Result<Integer> count(SitesTypeTop record) {
        return Result.success(sitesTypeTopService.count(record));
    }

    @RequestMapping("insert")
    @ResponseBody
    public Result<Integer> insertSelective(SitesTypeTop record) {
        return Result.success(sitesTypeTopService.insertSelective(record));
    }

    @RequestMapping("update")
    @ResponseBody
    public Result<Integer> updateByPrimaryKeySelective(SitesTypeTop record) {
        return Result.success(sitesTypeTopService.updateByPrimaryKeySelective(record));
    }

    @RequestMapping("selectByPage")
    @ResponseBody
    public Result<Page<List<SitesTypeTop>>> selectByPage(Page<SitesTypeTop> page) {
        List<SitesTypeTop> list = null;
        page = page.sequentialDisplayCalculate(sitesTypeTopService.count(page.getObj()));
        if (page.getTotalCount() > 0) {
            list = sitesTypeTopService.selectByPage(page);
        }
        Page<List<SitesTypeTop>> result = new Page<List<SitesTypeTop>>(page, list);
        return Result.success(result);
    }

    @RequestMapping("deleteByCondition1")
    @ResponseBody
    public Result<Integer> deleteByCondition(SitesTypeTop record) {
        return Result.success(sitesTypeTopService.deleteByCondition(record));
    }

    @RequestMapping("delete1")
    @ResponseBody
    public Result<Integer> deleteByPrimaryKey(@Param("typeId") Integer typeId, @Param("siteId") Integer siteId) {
        return Result.success(sitesTypeTopService.deleteByPrimaryKey(typeId, siteId));
    }

}
